//
//  GRSystemSettingViewController.m
//  YC_GRice
//
//  Created by LiuFeng on 2018/7/14.
//  Copyright © 2018年 YeCai. All rights reserved.
//

#import "GRSystemSettingViewController.h"
#import "GRMyInfomationViewController.h"
#import "GRAboutRiceViewController.h"

#import "GRSystemSettingViewCell.h"
#import "GRMyCommonHeaderView.h"

@interface GRSystemSettingViewController ()

{
    NSArray *systemSettings;
}

@end

@implementation GRSystemSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    systemSettings = @[@"我的资料", @"清除缓存", @"关于我们", @"退出登录"];
    // Uncomment the following line to preserve selection between presentations.
    GRMyCommonHeaderView *headerView = [[GRMyCommonHeaderView alloc] initWithFrame:CGRectMake(0, 0, KscreenWidth, 55)];
    headerView.textLabel.text        = @"设置";
    self.tableView.tableHeaderView = headerView;
    self.tableView.tableFooterView = [UIView new];
    
    self.tableView.rowHeight       = 50;
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    [self.tableView registerNib:[UINib nibWithNibName:@"GRSystemSettingViewCell" bundle:nil] forCellReuseIdentifier:@"GRSystemSettingViewCell"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return systemSettings.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    GRSystemSettingViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GRSystemSettingViewCell" forIndexPath:indexPath];
    if (indexPath.row == 1) {
        cell.instructions.hidden = NO;
        cell.instructions.text   = [self cachesize];
    }else {
        cell.instructions.hidden = YES;
    }
    cell.titleLabel.text = systemSettings[indexPath.row];
    return cell;
}



-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    switch (indexPath.row) {
        case 0:{
            GRMyInfomationViewController *infomation = [[GRMyInfomationViewController alloc] initWithStyle:UITableViewStylePlain];
            [self.navigationController pushViewController:infomation animated:YES];
        }
            break;
        case 1:{
            [[SDImageCache sharedImageCache] clearDiskOnCompletion:^{
                [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
            }];
        }
            break;
        
        case 2:{
            GRAboutRiceViewController *about = [[GRAboutRiceViewController alloc] init];
            [self.navigationController pushViewController:about animated:YES];
        }
            break;
            
        default:{
            [[GRUserBasisInfo shareBasis] LoginOut];
            [self.navigationController popViewControllerAnimated:YES];
        }
            break;
    }
}

- (NSString *)cachesize {
    NSInteger size = [[SDImageCache sharedImageCache] getSize];
    CGFloat cache  = size/1024.0/1024.0;
    return [NSString stringWithFormat:@"%.2fM",cache];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
